﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QLKS10_11.BLL;

namespace QLKS10_11
{
    public partial class form_phong : Form
    {
        public form_phong()
        {
            InitializeComponent();
        }
        //*************************************************//
        public static form_phong Instance()
        {
            if (_instance == null)
            {
                _instance = new form_phong();
            }
            return _instance;
        }
        private static form_phong _instance;
        private void btn_back_Click(object sender, EventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Show();
            this.Hide();
        }
        // Khi đóng Form2 thì dừng luôn chương trình!
        // Nếu không có hàm này thì khi đóng Form2, Form1 vẫn đang chạy ẩn.
        private void form_phong_FormClosed(object sender, FormClosedEventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Dispose();
        }
        /***********************************************************/
        Phong_BLL phong = new Phong_BLL();
        private void form_phong_Load(object sender, EventArgs e)
        {
            //khi form load len khong cho nguoi dung tu sua danh sach
            gridView1.OptionsBehavior.Editable = false;
            btn_luu.Enabled = false;
            phong.HienThi(gc_phong, bd_phong);
        }
        private void btn_them_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
            DataRow row = phong.NewRow();
            row["tenphong"] = "";
            row["loai"] = "";
            row["gia"] = 1;
            row["chitiet"] ="";
            row["tinhtrangphong"] = "";
            phong.Add(row);
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            if (gridView1.RowCount > 0)
            {
                if (MessageBox.Show("Ban co chat muon xoa phong khong ?", "Xoa phong", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    bd_phong.BindingSource.RemoveCurrent();
                    phong.Save();
                }
            }
            else MessageBox.Show("Dach sach phong rong.");
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            bd_phong.BindingSource.MoveNext();
            bindingNavigatorPositionItem.Focus();
            phong.Save();
            MessageBox.Show("Luu thanh cong");
        }
        
        //*************************************************//
    }
}
